﻿using System;
using System.Windows;
using System.Windows.Controls;
using ParseControls;

namespace ParseOnlineAdmin
{
    /// <summary>
    /// Interaction logic for ParseAppsConfigView.xaml
    /// </summary>
    public partial class ParseAppsConfigView : UserControl
    {
        public ParseAppsConfigView()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (this.txtName.Text != string.Empty &&
                this.txtKey.Text != string.Empty &&
                this.txtSecret.Text != string.Empty)
            {
                // Item 
                ParseApp _app = new ParseApp();
                _app.GUID = Guid.NewGuid();
                _app.Name = this.txtName.Text;
                _app.Key = this.txtKey.Text;
                _app.Secret = this.txtSecret.Text;

                // Package 
                ParseOne.Package.Apps.Add(_app);
                ParseOne.Package.Save();
                ParseOne.ReloadPackage();

                ParseOne.InformationSending(new ParseCustomEventArgs("Apps:Refresh"));

                // Close Panel 
                ParseOne.InformationSending(new ParseCustomEventArgs("Panel:Close"));
            }
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            ParseOne.InformationSending(new ParseCustomEventArgs("Apps:Refresh"));

            // Close Panel 
            ParseOne.InformationSending(new ParseCustomEventArgs("Panel:Close"));
        }

        private void btnDeleteApp_Click(object sender, RoutedEventArgs e)
        {
            ParseOne.InformationSending(new ParseCustomEventArgs("App:Current:Delete"));

            // Close Panel 
            ParseOne.InformationSending(new ParseCustomEventArgs("Panel:Close"));
        }
    }
}
